$(()=>{

    if (success){
        layer.msg("添加成功");
        setTimeout(function (){
            parent.location.reload();
        },500);
    }
    //设置出厂日期选择框
    laydate.render({
        elem: "#productionDate"
    });

    //设置错误弹窗
    if (error){
        layer.alert(error);
    }
    //提交按钮事件
    $("#confirm").click(function (e){
        e.preventDefault();

        //前端的校验
        let commodityId = $("#commodityId").val();
        let commodityName = $("#commodityName").val();
        let commodityType = $("#commodityType").val();
        let supply = $("#supply").val();
        let price = $("#price").val();
        let productionDate = $("#productionDate").val();

        if (commodityId === ""){
            layer.alert("商品编号不允许为空");
        }else if (commodityName === ""){
            layer.alert("商品名称不允许为空");
        }else if (commodityType === ""){
            layer.alert("商品类型不允许为空");
        }else if (supply === ""){
            layer.alert("供应商不允许为空");
        }else if (price === ""){
            layer.alert("商品价格不允许为空");
        }else if (productionDate === ""){
            layer.alert("出厂日期不允许为空");
        }else{
            //通过前端校验,向后台提交数据
            $("#commodityForm").submit();//使用表单提交
        }


    });
});